package com.itkjb.leisurely.center;

import com.itkjb.leisurely.center.support.CenterJwtTokenEnhancer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.request.RequestContextListener;

/**
 * Copyright (C), 2018-2099
 * FileName: ApiApplication
 * @Author:   lix
 * Date:     2019-04-22 10:17
 * Description: api -启动类
 * Version: V1.0.0
 */
@SpringBootApplication(scanBasePackages = "com.itkjb")
@Slf4j
public class CenterApplication {
    public static void main(String[] args) {
        SpringApplication.run(CenterApplication.class,args);
    }

    @Bean
    public RestTemplate getRestTemplate(){
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate;
    }

    @Bean("jwtTokenEnhancer")
    @Primary
    public TokenEnhancer jwtTokenEnhancer(){
        log.debug("loading  TokenEnhancer Bean with: "+ CenterJwtTokenEnhancer.class.getName());
        return new CenterJwtTokenEnhancer();
    }

    /*
    @Bean
    public RequestInterceptor requestInterceptor(){
        return new FeignBasicAuthRequestInterceptor();
    }*/

    /**
     * 监听器：监听HTTP请求事件
     * 解决RequestContextHolder.getRequestAttributes()空指针问题
     * @return
     */
    @Bean
    public RequestContextListener requestContextListener(){
        return new RequestContextListener();
    }
}
